home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 20
/
Aminet 20 (1997)(GTI - Schatztruhe)[!][Aug 1997].iso
/
Aminet
/
comm
/
misc
/
net_time.lha
/
net_time
/
Net-time.e
< prev
next >
Wrap
Text File
|
1997-06-23
|
11KB
|
374 lines
MODULE 'intuition/intuition',
'graphics/displayinfo','graphics/text','graphics/rastport','wb',
'tools/file','dos/datetime','dos/dos','dos/dostags',
'workbench/workbench','icon','workbench/startup',
'gadtools','libraries/gadtools'
CONST VERSION=37, /* Minimum V2.0 (of course) */
WIN_FLAGS = WFLG_DRAGBAR OR WFLG_DEPTHGADGET OR
WFLG_NOCAREREFRESH OR WFLG_ACTIVATE,
WIN_FLAGSB = WFLG_CLOSEGADGET OR WFLG_DRAGBAR OR
WFLG_DEPTHGADGET OR WFLG_NOCAREREFRESH OR WFLG_ACTIVATE,
WIN_IDCMP = IDCMP_REFRESHWINDOW OR IDCMP_GADGETUP OR
IDCMP_ACTIVEWINDOW,
WIN_IDCMPB = IDCMP_CLOSEWINDOW OR IDCMP_REFRESHWINDOW OR
IDCMP_GADGETUP OR IDCMP_ACTIVEWINDOW,
GRY=0,BLK=1,WHT=2,BLU=3, /* WB 2.0 colours */
RECESSED = 2,
R=120,
MAXCOUNT=50 /* # of times to draw shap before changing it */
ENUM NOERROR=NIL,
NOMEM,
NOLIBRARY,
NOKICK,
NOLOCK,
NOVISUAL,
NOWINDOW,
NOGADGETS,
NONE,NOCXLIB,BADARGS,NOBROKER,NOPORT,NOICONLIB,NOWBLIB
RAISE NOMEM IF New()=NIL,
NOLIBRARY IF OpenLibrary()=NIL,
NOKICK IF KickVersion()=NIL,
NOLOCK IF LockPubScreen()=NIL,
NOVISUAL IF GetVisualInfoA()=NIL,
NOWINDOW IF OpenWindow()=NIL,
NOGADGETS IF CreateGadgetA()=NIL,
NOGADGETS IF CreateContext()=NIL
DEF wnd :PTR TO window, wndl :PTR TO window,
rast :PTR TO rastport,
scr, visual, context, lastgad,
thistask, origpri,
connection,terminal,e,f,h,j,l,m,n,o,p,q,x,y,
logstr[192] :STRING,lstr[20] :STRING,
gstr[30] :STRING,month,
loglist[13]:LIST,
myport,appitem,appmsg,messagelist :PTR TO LONG,
result,
myargs:PTR TO LONG,do:PTR TO diskobject,
string[200]:STRING,wbm:PTR TO wbstartup,rg:PTR TO wbarg,
dir,pname,z[200]:STRING,path[30]:STRING
->************************ Main ************************************
PROC main() HANDLE
KickVersion(VERSION)
workbenchbase:=OpenLibrary('workbench.library',37)
myport:=CreateMsgPort()
appitem:=AddAppMenuItemA(0,0,'Net-time',myport,NIL)
f:=NIL
myargs:=[0,0,0] -> static array for the arg's
wbm:=wbmessage
-> open the resources we need...
IF (workbenchbase:=OpenLibrary('workbench.library',37))=NIL THEN Raise(NOWBLIB)
IF (iconbase:=OpenLibrary('icon.library',37))=NIL THEN Raise(NOICONLIB)
-> compute program's path and name, i.e. get it from the wbmessage */
IF wbmessage
IF wbm.numargs>0
rg:=wbm.arglist+((wbm.numargs-1)*SIZEOF wbarg)
dir:=CurrentDir(rg[].lock)
pname:=rg.name
ELSE
pname:='progdir:Net-time'
ENDIF
ELSE
pname:=StringF(string,'progdir:\s',GetProgramName(z,200) BUT z)
ENDIF
-> do we have an icon?
IF do:=GetDiskObject(pname)
myargs[0]:=FindToolType(do.tooltypes,'W_POSX')
myargs[1]:=FindToolType(do.tooltypes,'W_POSY')
myargs[2]:=FindToolType(do.tooltypes,'LOG_PATH')
IF myargs[0] THEN x:=Val(myargs[0]) ELSE x:=10
IF myargs[1] THEN y:=Val(myargs[1]) ELSE y:=15
IF myargs[2] THEN StringF(path,'\sNettimelog',myargs[2])
ELSE
f:=1
ENDIF
l:=1
wnd:=NIL
wndl:=NIL
->Read logfile
getmonth()
file()
gstr:=MidStr(gstr,logstr,(month*8),8)
o:=(Val(MidStr(lstr,gstr,1,3)))*3600
o:=(Val(MidStr(lstr,gstr,4,2)))*60+o
o:=o+(Val(MidStr(lstr,gstr,6,2)))
thistask:=FindTask(NIL)
gadtoolsbase:=OpenLibrary({txt_gadtools},VERSION)
CreateContext({context})
lastgad:=context
origpri:=setpri(-1)
LOOP
-> ********** Mainloop ********************************************
terminal:=And(Char($BFD000),%10000000)
connection:=And(Char($BFD000),%00100000)
appmsg:=GetMsg(myport)
IF appmsg<>0 THEN req()
IF f THEN Raise(NIL)
-> did the carrier start or stop?
IF connection=%00100000
-> IF terminal=%10000000
CurrentTime({h},{m})
n:=h-o ->n=startid-sparadlogtid
IF l=0
savelog()
l:=1
closewin()
ENDIF
ELSE
IF l=1
openwin()
l:=0
ENDIF
CurrentTime({h},{m})
IF (o+n)>h THEN n:=h-o ->if the counter resets
o:=h-n
e:=o/3600 ->timmar
p:=o-(e*3600)/60 ->minuter
q:=o-(p*60)-(e*3600) ->sekunder
Colour(1,0) ; SetTopaz(8)
StringF(gstr,'\z\d[3]:\z\d[2]:\z\d[2]',e,p,q)
TextF(3,8,'\s',gstr)
ENDIF
-> avoid busy polling
Delay(5)
ENDLOOP
EXCEPT
IF scr THEN UnlockPubScreen(NIL,NIL)
IF wnd THEN CloseWindow(wnd)
IF wndl THEN CloseWindow(wndl)
IF context THEN FreeGadgets(context)
IF visual THEN FreeVisualInfo(visual)
IF gadtoolsbase THEN CloseLibrary(gadtoolsbase)
RemoveAppMenuItem(appitem); DeleteMsgPort(myport)
ENDPROC
->****************************** END ************************************
PROC openwin()
/* open our window.. */
scr:=LockPubScreen(NIL)
visual:=GetVisualInfoA(scr,NIL)
wnd:=OpenWindowTagList(NIL,
[ WA_FLAGS,WIN_FLAGS,WA_IDCMP,WIN_IDCMP,
WA_LEFT,x, WA_TOP,y,
WA_WIDTH,100, WA_HEIGHT,12,
WA_TITLE,'',
WA_GADGETS,context,NIL,NIL ])
UnlockPubScreen(NIL,scr)
scr:=NIL
rast:=stdrast:=wnd.rport
SetTopaz(8)
RefreshGadgets(context,wnd,NIL)
Gt_RefreshWindow(wnd,NIL)
ENDPROC
PROC closewin()
IF wnd THEN CloseWindow(wnd)
wnd:=NIL
ENDPROC
PROC file() HANDLE -> Checks if logfile exists, if not? oops!
DEF m,l,n,list
m,l:=readfile(path)
n:=countstrings(m,l)
list:=stringsinfile(m,l,n)
IF l=96 THEN StrCopy(logstr,m,96) ELSE Raise(NIL)
j:=l
EXCEPT
makelogfile()
oops()
ENDPROC
PROC oops()
StringF(gstr,'Make one|Oh-shit!')
result:=EasyRequestArgs(0,[20,0,0,{txt_req},gstr],0,NIL)
SELECT result
CASE 1
savelog()
DEFAULT
f:=1
ENDSELECT
ENDPROC
PROC makelogfile() -> Makes a empty logfile
DEF i
FOR i:=1 TO 12
loglist[i]:=i
ENDFOR
StrCopy(logstr,'',ALL)
FOR i:=1 TO 12
StrAdd(logstr,'00000000',ALL)
ENDFOR
ENDPROC
PROC savelog() -> update logstr and save it
DEF i,templogstr[120]:STRING
StrCopy(templogstr,'',ALL)
FOR i:=0 TO 11
IF i<>month
gstr:=MidStr(gstr,logstr,i*8,8)
StrAdd(templogstr,gstr,ALL)
ELSE
StringF(gstr,'\z\d[8]',q+(p*100)+(e*10000))
StrAdd(templogstr,gstr,ALL)
ENDIF
ENDFOR
StrCopy(logstr,templogstr,ALL)
writefile(path,logstr,96)
ENDPROC
PROC getmonth() ->Calculates year,day of year,month
DEF dt:datetime,ds:PTR TO datestamp,yr,sch,days,syr,da,
list:PTR TO LONG
list:=[31,28,31,30,31,30,31,31,30,31,30,31]
yr:=78
sch:=-1
syr:=2
da:=0
ds:=DateStamp(dt.stamp)
WHILE ds.days>sch
sch:=sch+365
IF ds.days>sch THEN yr:=yr+1
IF syr=4 AND ds.days>sch THEN sch:=sch+1
syr:=syr+1
IF syr=5 THEN syr:=1
ENDWHILE
days:=ds.days-(sch-365)
month:=1
IF syr=1 THEN list[2]:=29
WHILE days>(da+list[month])
month:=month+1
da:=da+list[month-2]
ENDWHILE
month:=month-1
ENDPROC
PROC printlog() ->Opens a window and prints the logfile
DEF i,tstr[20]:STRING
wndl:=OpenWindowTagList(NIL,
[ WA_FLAGS,WIN_FLAGSB,WA_IDCMP,WIN_IDCMPB,
WA_LEFT,230, WA_TOP,40,
WA_WIDTH,150, WA_HEIGHT,200,
WA_TITLE,'Net-time log',
WA_GADGETS,context,NIL,NIL ])
ActivateWindow(wndl)
Gt_RefreshWindow(wndl,NIL)
rast:=stdrast:=wndl.rport
Colour(1,0) ; SetTopaz(8)
messagelist:=[ 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep',
'Oct','Nov','Dec' ]
FOR i:=0 TO 11
IF month=i THEN StrCopy(tstr,'->',ALL) ELSE StrCopy(tstr,' ',ALL)
gstr:=MidStr(gstr,logstr,i*8+1,3)
StrAdd(tstr,gstr,ALL);StrAdd(tstr,':')
gstr:=MidStr(gstr,logstr,i*8+4,2)
StrAdd(tstr,gstr,ALL);StrAdd(tstr,':')
gstr:=MidStr(gstr,logstr,i*8+6,2)
StrAdd(tstr,gstr,ALL)
TextF(10,12*i+32,'\s \s ',messagelist[i],tstr)
ENDFOR
WHILE WaitIMessage(wndl)<>IDCMP_CLOSEWINDOW
ENDWHILE
CloseWindow(wndl)
wndl:=NIL
IF wnd<>NIL THEN rast:=stdrast:=wnd.rport
ENDPROC
PROC req()
StringF(gstr,'Loglist|About|Terminate')
result:=EasyRequestArgs(0,[20,0,0,{txt_about},gstr],0,NIL)
SELECT result
CASE 1
printlog()
CASE 2
about()
DEFAULT
f:=1
ENDSELECT
ENDPROC
PROC about()
DEF result,gstr[30]:STRING
StringF(gstr,'SKIP this!')
result:=EasyRequestArgs(0,[20,0,0,{txt_more},gstr],0,NIL)
ENDPROC
-> ++++++++++++++++++++ END OF MY PROC'S +++++++++++++++++++++++++++++++++
PROC setpri(pri)
ENDPROC SetTaskPri(thistask,pri)
txt_gadtools:
CHAR 'gadtools.library',0
txt_about:
CHAR ' Net-time\n\n',
'© COPYRIGHT 1997 Sören Forsberg\n\n',
'Written in AmigaE\n\n',
'E-mailware\n',
'sorenf@hem1.passagen.se\n',0
txt_req:
CHAR ' Net-time logfile damaged or missing ',0
txt_more:
CHAR 'Net-time V1.0 Copyright Sören Forsberg 97\n',
'This is a WB2+ onlinetime-log,timer program.\n',
'It shows your TOTAL onlinetime for the current month.\n',
'\qNO NEED TO CHECK A LOGFILE EVER AGAIN\q\n',
'It was written in AmigaE because\n',
'amos sucks and blitzbasic gurus.\n\n',
'Installation?\n',
'Easy just drop it in your WBStartup drawer.\n',
'Usage?\n',
'If you want to see the log, you will find net-time\n',
'in the tools-menu. There are 3 tooltypes to edit to\n',
'your liking.\n',
'Bugs? Probably,use at own risk.(works fine for me :))\n',
'Quirks?\n',
'As the program checks the carrierdetect-signal (CD)\n',
'to determine wether you are online or not it will \n',
'miss 1-10 seconds every login.\n',
' (But i belive all programs of this kind do?)\n',
'Status?\n',
'Emailware (If it stuck in your wbstartup).\n',
'Bugreports welcome.\n\n',
'E-Mail : sorenf@hem1.passagen.se\n',
'Irc : soren\n',
'Home-page : www.hem1.passagen.se\\sorenf\\index.html\n',0
/*
to do:
rätt tid vid månadsbyte+online
optimera (delay)
om DTR "Ditt modem är redan på ,forsätta iallafall?eller editera loggfilen
*/